package acm.蓝桥5;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.BitSet;

public class 外卖店优先级 {
    static int maxN = 100001;
    static int[][] logs = new int[maxN][2]; //0：时间，1：id
    static int[] cnt = new int[maxN];
    static BitSet set = new BitSet(maxN);
    static int n, m, t;

    public static void main(String[] args) {
        Reader sc = new Reader();
        n = sc.nextInt();
        m = sc.nextInt();
        t = sc.nextInt();
        for (int i = 0; i < m; i++) {
            logs[i][0] = sc.nextInt();
            logs[i][1] = sc.nextInt();
        }
        BitSet vis = new BitSet(n + 1);
        Arrays.sort(logs, 0, m, (a, b) -> a[0] - b[0]);

        int i = 0;
        int preTime=1;
        for (int time = logs[0][0]; time <= t; time = logs[i][0]) {
            while (i < m && logs[i][0] == time) {
                cnt[logs[i][1]] += 2;
                vis.set(logs[i][1]);
                if (cnt[logs[i][1]] >= 5) {
                    set.set(logs[i][1]);
                }
                i++;
            }
            vis.flip(1, n + 1);
            vis.stream().forEach(o -> {
                if (cnt[o] > 0) {
                    cnt[o]--;
                    if (cnt[o] <= 3) {
                        set.set(o, false);
                    }
                }
            });
            vis.clear();
            if (i == m) {
                break;
            }
        }
//        int last = logs[m - 1][0];
//        int diff = t - last;
//        if (diff > 0) {
//            for (int j = 0; j < n; j++) {
//                cnt[j] -= diff;
//                if (cnt[j] <= 3) {
//                    set.set(j, false);
//                }
//            }
//        }
        System.out.println(set.stream().count());
    }

    static class Reader {
        static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public static int nextInt() {
            try {
                in.nextToken();
            } catch (Exception ignored) {
            }
            return (int) in.nval;
        }
    }
}
